﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;


namespace TripLOAMobile
{   
    static class CheckTexture
    {

        #region Member public

        public const Int32 MINLENGTH = 1;
        public const int MAXSTEP = 5;

        #endregion


        #region Member private

        private static Regex rgxIS = new Regex(@"[?\()\+\#\=\[\]\{\}\£\&\%\:\;\$@]");
        private static Regex rgxUser = new Regex(@"[?\()\+\#\=\[\]\{\}\£\&\%\,\!\:\;\$@-]");
        private static Regex rgxPsw = new Regex(@"[?\()\+\#\=\[\]\{\}\£\&\%\*\,\!\:\.\;\-\$@-]");
        private static System.Drawing.Color customColor = System.Drawing.Color.FromArgb(255,98,102);

        #endregion


        #region Methods about CheckLogInInfo
        
        /// <summary>
        /// Control if the username or the password present some splelling mistake
        /// </summary>
        /// <param name="user">The username</param>
        /// <param name="pws">The password</param>
        /// <returns>false if there are some error, true otherwise</returns>
        public static bool CheckLogIn(TextBox user, TextBox psw)
        {
            if ((user.Text.Length < MINLENGTH) || (psw.Text.Length < MINLENGTH) || rgxUser.IsMatch(user.Text) || rgxPsw.IsMatch(psw.Text))
            {
                //user.Text = "Error!";
                user.BackColor = customColor;
                user.ForeColor = System.Drawing.Color.Navy;
                //psw.PasswordChar = char.MinValue;
                psw.Text = "";
                psw.BackColor = customColor;
                psw.ForeColor = System.Drawing.Color.Navy;
                return false; 
                   
            }
            return true;
        }

        
        #endregion

  

        #region Methods about CheckSearchInsertInfo


        /// <summary>
        /// Control if the information present some splelling mistake
        /// </summary>
        /// <param name="info">The departure or the destination of the travel</param>
        private static bool CheckTravelInfo(TextBox info)
        {
            if ((info.Text.Length < MINLENGTH) || rgxIS.IsMatch(info.Text))
            {
               
                info.BackColor = customColor;
                info.ForeColor = System.Drawing.Color.Navy;
                return false;
            }
            return true;
        }



        /// <summary>
        /// Control if the date of departure and the date of arrival are consistency
        /// </summary>
        /// <param name="dtpDeparture">The date of departure</param>
        /// <param name="dtpArrival">The date of arrival</param>
        /// <returns>false if the dates are not consistency, true otherwise</returns>
        private static bool CheckDateSearch(DateTimePicker dtpDeparture, DateTimePicker dtpArrival)
        {
            if ( !(dtpDeparture.Value.Date.CompareTo(dtpArrival.Value.Date) <= 0))
            { 
               
                return false;
            }
            else if (!(DateTime.Now.Date.CompareTo(dtpDeparture.Value.Date) <= 0))
            {
              
                return false;
            }
            else if (!(DateTime.Now.Date.CompareTo(dtpArrival.Value.Date) <= 0))
            {
                
                return false;
            }
            return true;
        }

        
        /// <summary>
        /// Control if the name of departure and name of destination present some splelling mistake.
        /// Control if the date of departure and the date of destination are consistency
        /// </summary>
        /// <param name="departure">The information about the departure of the travel</param>
        /// <param name="destination">The information about the destination of the travel</param>
        /// <returns>false if there are some error, true otherwise</returns>
        public static bool CheckSearchTravel(TextBox departure, TextBox destination)
        {
            return CheckTexture.CheckTravelInfo(departure) & CheckTexture.CheckTravelInfo(destination); 
        }
        
 
        #endregion

   }

}
